public class Solution {
    public void rotate(int[] nums, int k) {
        int n = nums.length;
        int[] newArr = new int[n];
        for (int i = 0; i < n; ++i) {
            newArr[(i + k) % n] = nums[i];
        }
        System.arraycopy(newArr, 0, nums, 0, n);
    }

    public static void main(String[] args) {
        // 创建一个测试用例
        int[] nums = {1, 2, 3, 4, 5, 6, 7};
        int k = 3;
        // 打印原始数组
        System.out.println("原始数组: ");
        for (int num : nums) {
            System.out.print(num + " ");
        }
        System.out.println();
        Solution solution = new Solution();
        solution.rotate(nums, k);
        // 打印旋转后的数组
        System.out.println("旋转 " + k + " 个位置后的数组: ");
        for (int num : nums) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}
